<template>


    <a-tree-select
            treeDataSimpleMode
            :treeDefaultExpandAll="treeDefaultExpandAll"
            :placeholder="placeholder"
            v-model="selectValue"
            :dropdown-style="{ maxHeight: '400px', overflow: 'auto' }"
            :tree-data="treeData"
            allowClear
            @change="onchange"
    />


</template>
<script>
    import {simpleTyeTree} from "../public/internal";

    export default {
        props: ['value','pushTop'],
        data() {
            return {
                selectValue: null,
                treeDefaultExpandAll: true,
                placeholder: "请选择图文分类",
                treeExpandedKeys: [],
                treeData: [], //图文分类树
                replaceFields: {id: "code", pid: "parentCode", key: "id", value: "code", title: "name"}
            };
        },
        methods: {
            onchange(value) {


             this.$emit('onSelect', value);
            },
            getTree() {
                simpleTyeTree().then(res => {
                    if (res.code === 0) {
                      let result = res.data.result;
                      if(this.pushTop){
                          let obj={  id: "0", label: "顶级分类", pId: "-1", value: "0"}
                          result.push(obj);
                      }




                        this.treeData =result;


                    }
                })
            }
        },
        //初始化图文分类树
        created() {
            this.getTree();
            this.selectValue = this.value;

        },
        watch: {
            value(val) {


                    this.selectValue = val;



            }
        }
    };
</script>
